package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class UtilContext {
    //存放常量的工具类
    public static final String USER_IN_SESSION = "USER_IN_SESSION";
    public static final String EXPRESSION_IN_SESSION = "EXPRESSION_IN_SESSION";

    //利用springMVC提供的工具类来获取getSession()
    public static HttpSession getSession() {
        ServletRequestAttributes attrs =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }

    public static Employee getCurrentUser() {
        return (Employee) getSession().getAttribute(USER_IN_SESSION);
    }

    public static void setCurrentUser(Employee employee) {
        getSession().setAttribute(USER_IN_SESSION, employee);
    }

    public static List<String> getExpression() {
        return (List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION);
    }

    public static void setExpression(List<String> list) {
        getSession().setAttribute(EXPRESSION_IN_SESSION, list);
    }


}
